package com.example.ex.mapper;

import com.example.ex.pojo.ChatMessage;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author zhou
* @description 针对表【chat_message】的数据库操作Mapper
* @createDate 2023-05-30 23:17:11
* @Entity com.example.ex.pojo.ChatMessage
*/
@Mapper
public interface ChatMessageMapper extends BaseMapper<ChatMessage> {
    @Select("select * from chat_message where (sendername = #{senderName} and receivername = #{receiverName}) or (sendername = #{receiverName} and receivername = #{senderName}) order by ID")
    List<ChatMessage> getRecord(String senderName, String receiverName);


    @Select("SELECT DISTINCT CASE WHEN sendername = #{username} THEN receivername WHEN receivername = #{username} THEN sendername END AS chat_partner FROM chat_system.chat_message WHERE #{username} IN (sendername, receivername)")
    List<String> getHistory(String username);
}




